import msg from "@/utils/msg.js"
import {
	BASE_URL
} from "@/config/index.js"


const upload = (tempFilePaths) => {
	return new Promise((resolve) => {
		uni.showLoading({
			title: '上传中...'
		})
		uni.uploadFile({
			url: BASE_URL + '/app-api/infra/file/upload',
			filePath: tempFilePaths,
			name: 'file',
			success: (uploadFileRes) => {
				uni.hideLoading()
				const data = JSON.parse(uploadFileRes.data);
				if (data.code === 0) {
					resolve(data)
				} else msg.toast("上传失败")
			},
			fail() {
				uni.hideLoading()
				msg.toast("上传失败")
			}
		});
	})
}

export default upload